<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of owlpersonal
 *
 * @author trung
 */
class Owl_Personal extends Owl_Db{

    function Owl_Personal(){
        $this->Owl_Db('personal');
    }

    function get_personal(){
        return $this->get_row('/personals/personal');
    }

    function insert_personals($data){
        $defaults = array(
                            'name' => '',
                            'password' => '',
                            'salt' => '',
                            'emails' => '',
                            'address' => '',
                            'office' => '',
                            'phones' => '',
                            'position' => '',
                            'degree' => 'GS',
                            'avatar' => '',
                            'interests' => array(),
                            'certifications' => array(),
                            'academics' => array()
                        );
        $data = Owl_System_Helper::array_merge($data, $defaults);
        
        return $this->insert('/personals', 'personal', $data);
    }

    function delete_personals(){        
        return $this->delete('/personals/personal');
    }

    function update_personals($data){
        
        $old_personal = $this->get_personal();

        if ($old_personal === false){
            $this->last_error = new Owl_Error('505','Personal does not exist');
            return false;
        }
        
        $defaults = array(
                            'name' => $old_personal['name'],
                            'password' => $old_personal['password'],
                            'salt' => $old_personal['salt'],
                            'emails' => $old_personal['emails'],
                            'address' => $old_personal['address'],
                            'office' => $old_personal['office'],
                            'phones' => $old_personal['phones'],
                            'position' => $old_personal['position'],
                            'degree' => $old_personal['degree'],
                            'avatar' => $old_personal['avatar'],
                            'interests' => $old_personal['interests'],
                            'certifications' => $old_personal['certifications'],
                            'academics' => $old_personal['academics']
                        );

        $data = Owl_System_Helper::array_merge($data, $defaults);
        $data = Owl_Format::esc_html_deep($data);
        return $this->update('/personals/personal','personal',$data);
    }

    function insert_interest($interest){
        if (empty ($interest))
            return false;
        if ($this->get_row('/personals/personal/interests[interest="'.$interest.'"]') !== false){
            $this->last_error = new Owl_Error('505', __('Interest is duplicate'));
            return false;
        }

        return $this->insert('/personals/personal/interests', 'interest', $interest);
    }

    function delete_interest($interest){
        if (empty ($interest))
            return false;
        return $this->delete('/personals/personal/interests/interest[.="'.$interest.'"]');
    }

    function insert_certificate($certification){
        if (empty ($certification))
            return false;
        if ($this->get_row('/personals/personal/certifications[certification="'.$certification.'"]') !== false){
            $this->last_error = new Owl_Error('505', __('Certification is duplicate'));
            return false;
        }
        return $this->insert('/personals/personal/certifications', 'certification', $certification);
    }

    function delete_certificate($certification){
        if (empty ($certification))
            return false;
        return $this->delete('/personals/personal/certifications/certification[.="'.$certification.'"]');
    }

    function change_password($old_password, $new_password) {
        //Check the old password first
        $personal_info = $this->get_personal();
        if (!empty($personal_info["password"]) && Owl_System_Helper::hash(trim($old_password), trim($personal_info["salt"])) != trim($personal_info["password"])) {
            //Fail
            $this->last_error = new Owl_Error('505', __('Old password is wrong'));
            return false;
        }
        else {
            $new_password = trim($new_password);
            //Generate new hashed password and salt
            $new_salt = Owl_System_Helper::generate_random_string(10, true, false);
            $new_hashed_password = Owl_System_Helper::hash($new_password, $new_salt);
            return $this->update_personals(array(
                "password" => $new_hashed_password,
                "salt" => $new_salt
            ));
        }
    }

    function get_personal_with_lang($lang) {
        $personal = $this->get_personal();
        $owl_ulang = new Owl_Ulang();

        $to_translate = array('name', 'office', 'position', 'degree', 'address');

        $translated = array();
        foreach ($to_translate as $term) {
            $translator = $owl_ulang->get_ulang($personal[$term]);
            if (translator == false) {
                return false;
            }
            $translated[] = ($translator[$lang]) ? $translator[$lang] : "";
        }
        
        return $translated;
    }

    function get_additional_info_with_lang($type, $lang) {
        $personal = $this->get_personal();
        $owl_ulang = new Owl_Ulang();

        $info_array = $personal[$type];
        if (empty ($info_array)) {
            return false;
        }

        $info_lang = array();
        foreach ($info_array as $info) {
            $translator = $owl_ulang->get_ulang($info);
            if ($translator !== false) {
                $info_lang[] = array(
                    'id' => $info,
                    'trans' => ($translator[$lang]) ? $translator[$lang] : ""
                );
            }
        }
        return $info_lang;
    }

    function print_personal_info() {
        $personal_info = $this->get_personal();
        $degree = (__($personal_info["degree"], true)) ? ", " . __($personal_info["degree"], true) : "";
        $to_print = array(
            "<b>" . __("Name") . "</b>: " . Owl_Format::esc_html(__($personal_info["name"], true)) . Owl_Format::esc_html($degree),
            "<b>" . __("Office") . "</b>: " . Owl_Format::make_nice_textarea_content(Owl_Format::esc_html(__($personal_info["office"], true))),
            "<b>" . __("Position") . "</b>: " . Owl_Format::esc_html(__($personal_info["position"], true)),
            "<b>" . __("Address") . "</b>: " . Owl_Format::make_nice_textarea_content(Owl_Format::esc_html(__($personal_info["address"], true))),
            "<b>" . __("Phone") . "</b>: " . preg_replace('/\s+/',', ',trim($personal_info["phones"])),
            "<b>" . __("Email") . "</b>: " . Owl_Format::make_clickable(preg_replace('/\s+/',', ',$personal_info["emails"]))
        );
        echo Owl_Html::make_it_list($to_print);
    }

    function print_academics() {
        $personal_info = $this->get_personal();
        if (is_array($personal_info["academics"])) {
            $to_print = array();
            foreach ($personal_info["academics"] as $academic) {
                $to_print[] = trim(Owl_Format::esc_html(__($academic, true)));
            }
            echo Owl_Html::make_it_list($to_print, false);
        }
        else {
            echo __("No information");
        }
    }

    function print_interests() {
        $personal_info = $this->get_personal();
        if (is_array($personal_info["interests"])) {
            $to_print = array();
            foreach ($personal_info["interests"] as $interest) {
                $to_print[] = trim(Owl_Format::esc_html(__($interest, true)));
            }
            echo Owl_Html::make_it_list($to_print, false);
        }
        else {
            echo __("No information");
        }
    }

    function print_certifications() {
        $personal_info = $this->get_personal();
        if (is_array($personal_info["certifications"])) {
            $to_print = array();
            foreach ($personal_info["certifications"] as $certification) {
                $to_print[] = trim(Owl_Format::esc_html(__($certification, true)));
            }
            echo Owl_Html::make_it_list($to_print, false);
        }
        else {
            echo __("No information");
        }
    }

    function print_personal_form() {
        $personal_info = $this->get_personal();
        echo '<form action="' . Owl_Link::ajax_url(false) . 'info-ajax.php" method="POST" id="personal-info-edit">' . "\n";
        Owl_Form::print_hidden(array(
            'name' => 'action',
            'value' => 'edit_personal_info'
        ));
        echo '<table class="form-table" border="0" cellspacing="0" cellpadding="0">';
        echo '<tbody>';

        //Language
        echo '<tr>';
        echo '<th>';
        Owl_Form::print_label(array(
            'value' => __("Language")
        ));
        echo '</th>';
        echo '<td>';
        Owl_Form::print_combo_box(array(
            'name' => 'lang',
            'value' => get_current_language(),
            'options' => Owl_Functions::get_available_languages(),
            'class' => 'form-combobox input-lang-changer'
        ));
        echo '</td>';
        echo '</tr>';
        
        //Name
        echo '<tr>';
        echo '<th>';
        Owl_Form::print_label(array(
            'value' => __("Name"),
            'for' => 'form-info-name'
        ));
        echo '</th>';
        echo '<td>';
        Owl_Form::print_textbox(array(
            'name' => 'info_name',
            'value' => trim(Owl_Format::esc_html(__($personal_info["name"], true, true))),
            'id' => 'form-info-name',
            'class' => 'form-textbox ' . Owl_Functions::build_validate_string(array('required'))
        ));
        echo '</td>';
        echo '</tr>';

        //Office
        echo '<tr>';
        echo '<th>';
        Owl_Form::print_label(array(
            'value' => __("Office"),
            'for' => 'form-info-office'
        ));
        echo '</th>';
        echo '<td>';
        Owl_Form::print_textarea(array(
            'name' => 'info_office',
            'value' => trim(Owl_Format::esc_html(__($personal_info["office"], true, true))),
            'id' => 'form-info-office',
            'rows' => 3
        ));
        echo '</td>';
        echo '</tr>';

        //Position
        echo '<tr>';
        echo '<th>';
        Owl_Form::print_label(array(
            'value' => __("Position"),
            'for' => 'form-info-position'
        ));
        echo '</th>';
        echo '<td>';
        Owl_Form::print_textbox(array(
            'name' => 'info_position',
            'value' => trim(Owl_Format::esc_html(__($personal_info["position"], true, true))),
            'id' => 'form-info-position'
        ));
        echo '</td>';
        echo '</tr>';

        //Degree
        echo '<tr>';
        echo '<th>';
        Owl_Form::print_label(array(
            'value' => __("Degree"),
            'for' => 'form-info-degree'
        ));
        echo '</th>';
        echo '<td>';
        Owl_Form::print_textbox(array(
            'name' => 'info_degree',
            'value' => trim(Owl_Format::esc_html(__($personal_info["degree"], true, true))),
            'id' => 'form-info-degree'
        ));
        echo '</td>';
        echo '</tr>';

        //Address
        echo '<tr>';
        echo '<th>';
        Owl_Form::print_label(array(
            'value' => __("Address"),
            'for' => 'form-info-address'
        ));
        echo '</th>';
        echo '<td>';
        Owl_Form::print_textarea(array(
            'name' => 'info_address',
            'value' => trim(Owl_Format::esc_html(__($personal_info["address"], true, true))),
            'id' => 'form-info-address',
            'rows' => 3
        ));
        echo '</td>';
        echo '</tr>';

        //Phones
        echo '<tr>';
        echo '<th>';
        Owl_Form::print_label(array(
            'value' => __("Phone")
        ));
        echo '</th>';
        echo '<td id="input-phones">';
        $phones = trim($personal_info["phones"]);
        if (empty($phones)) {
            echo "<div>";
            Owl_Form::print_textbox(array(
                'name' => 'info_phones[0]',
                'class' => 'form-textbox multi-input last ' . Owl_Functions::build_validate_string(array('phone'))
            ));
            echo '<a href="#" rel="input-phones" class="delete-phone-input info-extra delete"><span>' . __("Delete") . '</span></a>';
            echo '<a href="#" rel="input-phones" class="add-phone-input info-extra add"><span>' . __("Add") . '</span></a>';
            echo "</div>";
        }
        else {
            $phones = preg_split('/\s+/', $phones);
            for ($i = 0; $i < count($phones) - 1; $i++) {
                echo "<div>";
                Owl_Form::print_textbox(array(
                    'name' => "info_phones[$i]",
                    'value' => $phones[$i],
                    'class' => 'form-textbox multi-input ' . Owl_Functions::build_validate_string(array('phone'))
                ));
                echo '<a href="#" rel="input-phones" class="delete-phone-input info-extra delete"><span>' . __("Delete") . '</span></a>';
                echo "</div>";
            }
            echo "<div>";
            Owl_Form::print_textbox(array(
                'name' => "info_phones[$i]",
                'value' => $phones[$i],
                'class' => 'form-textbox multi-input last ' . Owl_Functions::build_validate_string(array('phone'))
            ));
            echo '<a href="#" rel="input-phones" class="delete-phone-input info-extra delete"><span>' . __("Delete") . '</span></a>';
            echo '<a href="#" rel="input-phones" class="add-phone-input info-extra add"><span>' . __("Add") . '</span></a>';
            echo "</div>";
        }
        echo '</td>';
        echo '</tr>';

        //Emails
        echo '<tr>';
        echo '<th>';
        Owl_Form::print_label(array(
            'value' => __("Email")
        ));
        echo '</th>';
        echo '<td id="input-emails">';
        $emails = trim($personal_info["emails"]);
        if (empty($emails)) {
            echo "<div>";
            Owl_Form::print_textbox(array(
                'name' => 'info_emails[0]',
                'class' => 'form-textbox multi-input last ' . Owl_Functions::build_validate_string(array('email'))
            ));
            echo '<a href="#" rel="input-emails" class="delete-email-input info-extra delete"><span>' . __("Delete") . '</span></a>';
            echo '<a href="#" rel="input-emails" class="add-email-input info-extra add"><span>' . __("Add") . '</span></a>';
            echo "</div>";            
        }
        else {
            $emails = preg_split('/\s+/', $emails);
            for ($i = 0; $i < count($emails) - 1; $i++) {
                echo "<div>";
                Owl_Form::print_textbox(array(
                    'name' => "info_emails[$i]",
                    'value' => $emails[$i],
                    'class' => 'form-textbox multi-input ' . Owl_Functions::build_validate_string(array('email'))
                ));
                echo '<a href="#" rel="input-emails" class="delete-email-input info-extra delete"><span>' . __("Delete") . '</span></a>';
                echo "</div>";
            }
            echo "<div>";
            Owl_Form::print_textbox(array(
                'name' => "info_emails[$i]",
                'value' => $emails[$i],
                'class' => 'form-textbox multi-input last ' . Owl_Functions::build_validate_string(array('email'))
            ));
            echo '<a href="#" rel="input-emails" class="delete-email-input info-extra delete"><span>' . __("Delete") . '</span></a>';
            echo '<a href="#" rel="input-emails" class="add-email-input info-extra add"><span>' . __("Add") . '</span></a>';
            echo "</div>";
        }
        echo '</td>';
        echo '</tr>';

        //Ajax feedback
        echo '<tr>';
        echo '<td colspan="2">';
        Owl_Default_Content::print_ajax_feedback(false);
        echo '</td>';
        echo '</tr>';

        //Button
        echo '<tr>';
        echo '<td class="form-button-pane" colspan="2">';
        echo '<img src="' . Owl_Link::image_url(false) . 'default/ajax-load.gif" class="ajax-load" alt="Ajax load" />';
        Owl_Form::print_button(array(
            'name' => 'submit',
            'value' => __('Save'),
            'class' => 'form-button info-ajax-submit',
            'title' => 'personal-info-edit'
        ));
         Owl_Form::print_button(array(
            'name' => 'cancel',
            'value' => __('Cancel'),
            'class' => 'form-button info-cancel',
            'title' => 'personal-info'
        ));
        echo '</td>';
        echo '</tr>';
        
        echo '</tbody>';
        echo '</table>';
        echo '</form>';
    }

    function print_academics_form() {
        $personal_info = $this->get_personal();
        echo '<form action="' . Owl_Link::ajax_url(false) . 'info-ajax.php" method="POST" id="academics-edit">' . "\n";
        Owl_Form::print_hidden(array(
            'name' => 'action',
            'value' => 'edit_academics',
        ));
        echo '<table class="form-table" border="0" cellspacing="0" cellpadding="0">';
        echo '<tbody>';

        //Language
        echo '<tr>';
        echo '<th>';
        Owl_Form::print_label(array(
            'value' => __("Language")
        ));
        echo '</th>';
        echo '<td>';
        Owl_Form::print_combo_box(array(
            'name' => 'lang',
            'value' => get_current_language(),
            'options' => Owl_Functions::get_available_languages(),
            'class' => 'form-combobox input-lang-changer-special'
        ));
        echo '</td>';
        echo '</tr>';

        //Academics
        echo '<tr>';
        echo '<th>';
        Owl_Form::print_label(array(
            'value' => __("Academics record")
        ));
        echo '</th>';
        echo '<td id="input-academics">';
        $academics = $personal_info["academics"];
        if (!is_array($academics)) {
            echo "<div>";
            Owl_Form::print_textarea(array(
                'name' => 'academics[0]',
                'class' => 'form-textarea multi-input last',
                'rows' => 3
            ));
            Owl_Form::print_hidden(array(
                'name' => 'academics_hidden[0]',
                'value' => 'new_input',
                'class' => 'multi-input-hidden'
            ));
            echo '<a href="#" rel="input-academics" class="delete-academic-input info-extra delete"><span>' . __("Delete") . '</span></a>';
            echo '<a href="#" rel="input-academics" class="add-academic-input info-extra add"><span>' . __("Add") . '</span></a>';
            echo "</div>";
        }
        else {
            for ($i = 0; $i < count($academics) - 1; $i++) {
                echo "<div>";
                Owl_Form::print_textarea(array(
                    'name' => "academics[$i]",
                    'value' => trim(Owl_Format::esc_html(__($academics[$i], true, true))),
                    'class' => 'form-textarea multi-input',
                    'rows' => 3
                ));
                Owl_Form::print_hidden(array(
                    'name' => "academics_hidden[$i]",
                    'value' => $academics[$i],
                    'class' => 'multi-input-hidden'
                ));
                echo '<a href="#" rel="input-academics" class="delete-academic-input info-extra delete"><span>' . __("Delete") . '</span></a>';
                echo "</div>";
            }
            echo "<div>";
            Owl_Form::print_textarea(array(
                'name' => "academics[$i]",
                'value' => trim(Owl_Format::esc_html(__($academics[$i], true, true))),
                'class' => 'form-textarea multi-input last',
                'rows' => 3
            ));
        
            Owl_Form::print_hidden(array(
                'name' => "academics_hidden[$i]",
                'value' => $academics[$i],
                'class' => 'multi-input-hidden'
            ));
            echo '<a href="#" rel="input-academics" class="delete-academic-input info-extra delete"><span>' . __("Delete") . '</span></a>';
            echo '<a href="#" rel="input-academics" class="add-academic-input info-extra add"><span>' . __("Add") . '</span></a>';
            echo "</div>";
        }
        echo '</td>';
        echo '</tr>';

        //Ajax feedback
        echo '<tr>';
        echo '<td colspan="2">';
        Owl_Default_Content::print_ajax_feedback(false);
        echo '</td>';
        echo '</tr>';

        //Button
        echo '<tr>';
        echo '<td class="form-button-pane" colspan="2">';
        echo '<img src="' . Owl_Link::image_url(false) . 'default/ajax-load.gif" class="ajax-load" alt="Ajax load" />';
        Owl_Form::print_button(array(
            'name' => 'submit',
            'value' => __('Save'),
            'class' => 'form-button info-ajax-submit',
            'title' => 'academics-edit'
        ));
         Owl_Form::print_button(array(
            'name' => 'cancel',
            'value' => __('Cancel'),
            'class' => 'form-button info-cancel',
            'title' => 'academics'
        ));
        echo '</td>';
        echo '</tr>';


        echo '</tbody>';
        echo '</table>';
        echo '</form>';
    }

    function print_interests_form() {
        $personal_info = $this->get_personal();
        echo '<form action="' . Owl_Link::ajax_url(false) . 'info-ajax.php" method="POST" id="interests-edit">' . "\n";
        Owl_Form::print_hidden(array(
            'name' => 'action',
            'value' => 'edit_interests'
        ));
        echo '<table class="form-table" border="0" cellspacing="0" cellpadding="0">';
        echo '<tbody>';

        //Language
        echo '<tr>';
        echo '<th>';
        Owl_Form::print_label(array(
            'value' => __("Language")
        ));
        echo '</th>';
        echo '<td>';
        Owl_Form::print_combo_box(array(
            'name' => 'lang',
            'value' => get_current_language(),
            'options' => Owl_Functions::get_available_languages(),
            'class' => 'form-combobox input-lang-changer-special'
        ));
        echo '</td>';
        echo '</tr>';

        //Interests
        echo '<tr>';
        echo '<th>';
        Owl_Form::print_label(array(
            'value' => __("Interests")
        ));
        echo '</th>';
        echo '<td id="input-interests">';
        $interests = $personal_info["interests"];
        if (!is_array($interests)) {
            echo "<div>";
            Owl_Form::print_textarea(array(
                'name' => 'interests[0]',
                'class' => 'form-textarea multi-input last',
                'rows' => 3
            ));
            Owl_Form::print_hidden(array(
                'name' => 'interests_hidden[0]',
                'value' => 'new_input',
                'class' => 'multi-input-hidden'
            ));
            echo '<a href="#" rel="input-interests" class="delete-interest-input info-extra delete"><span>' . __("Delete") . '</span></a>';
            echo '<a href="#" rel="input-interests" class="add-interest-input info-extra add"><span>' . __("Add") . '</span></a>';
            echo "</div>";
        }
        else {
            for ($i = 0; $i < count($interests) - 1; $i++) {
                echo "<div>";
                Owl_Form::print_textarea(array(
                    'name' => "interests[$i]",
                    'value' => trim(Owl_Format::esc_html(__($interests[$i], true, true))),
                    'class' => 'form-textarea multi-input',
                    'rows' => 3
                ));
                Owl_Form::print_hidden(array(
                    'name' => "interests_hidden[$i]",
                    'value' => $interests[$i],
                    'class' => 'multi-input-hidden'
                ));
                echo '<a href="#" rel="input-interests" class="delete-interest-input info-extra delete"><span>' . __("Delete") . '</span></a>';
                echo "</div>";
            }
            echo "<div>";
            Owl_Form::print_textarea(array(
                'name' => "interests[$i]",
                'value' => trim(Owl_Format::esc_html(__($interests[$i], true, true))),
                'class' => 'form-textarea multi-input last',
                'rows' => 3
            ));
            Owl_Form::print_hidden(array(
                'name' => "interests_hidden[$i]",
                'value' => $interests[$i],
                'class' => 'multi-input-hidden'
            ));
            echo '<a href="#" rel="input-interests" class="delete-interest-input info-extra delete"><span>' . __("Delete") . '</span></a>';
            echo '<a href="#" rel="input-interests" class="add-interest-input info-extra add"><span>' . __("Add") . '</span></a>';
            echo "</div>";
        }
        echo '</td>';
        echo '</tr>';

        //Ajax feedback
        echo '<tr>';
        echo '<td colspan="2">';
        Owl_Default_Content::print_ajax_feedback(false);
        echo '</td>';
        echo '</tr>';

        //Button
        echo '<tr>';
        echo '<td class="form-button-pane" colspan="2">';
        echo '<img src="' . Owl_Link::image_url(false) . 'default/ajax-load.gif" class="ajax-load" alt="Ajax load" />';
        Owl_Form::print_button(array(
            'name' => 'submit',
            'value' => __('Save'),
            'class' => 'form-button info-ajax-submit',
            'title' => 'interests-edit'
        ));
         Owl_Form::print_button(array(
            'name' => 'cancel',
            'value' => __('Cancel'),
            'class' => 'form-button info-cancel',
            'title' => 'interests'
        ));
        echo '</td>';
        echo '</tr>';
        

        echo '</tbody>';
        echo '</table>';
        echo '</form>';
    }

    function print_certifications_form() {
        $personal_info = $this->get_personal();
        echo '<form action="' . Owl_Link::ajax_url(false) . 'info-ajax.php" method="POST" id="certifications-edit">' . "\n";
        Owl_Form::print_hidden(array(
            'name' => 'action',
            'value' => 'edit_certifications'
        ));
        echo '<table class="form-table" border="0" cellspacing="0" cellpadding="0">';
        echo '<tbody>';

        //Language
        echo '<tr>';
        echo '<th>';
        Owl_Form::print_label(array(
            'value' => __("Language")
        ));
        echo '</th>';
        echo '<td>';
        Owl_Form::print_combo_box(array(
            'name' => 'lang',
            'value' => get_current_language(),
            'options' => Owl_Functions::get_available_languages(),
            'class' => 'form-combobox input-lang-changer-special'
        ));

        echo '</td>';
        echo '</tr>';

        //Certifications
        echo '<tr>';
        echo '<th>';
        Owl_Form::print_label(array(
            'value' => __("Certifications")
        ));
        echo '</th>';
        echo '<td id="input-certifications">';
        $certifications = $personal_info["certifications"];
        if (!is_array($certifications)) {
            echo "<div>";
            Owl_Form::print_textarea(array(
                'name' => 'certifications[0]',
                'class' => 'form-textarea multi-input last',
                'rows' => 3
            ));
            Owl_Form::print_hidden(array(
                'name' => 'certifications_hidden[0]',
                'value' => 'new_input',
                'class' => 'multi-input-hidden'
            ));
            echo '<a href="#" rel="input-certifications" class="delete-certification-input info-extra delete"><span>' . __("Delete") . '</span></a>';
            echo '<a href="#" rel="input-certifications" class="add-certification-input info-extra add"><span>' . __("Add") . '</span></a>';
            echo "</div>";
        }
        else {
            for ($i = 0; $i < count($certifications) - 1; $i++) {
                echo "<div>";
                Owl_Form::print_textarea(array(
                    'name' => "certifications[$i]",
                    'value' => trim(Owl_Format::esc_html(__($certifications[$i], true, true))),
                    'class' => 'form-textarea multi-input',
                    'rows' => 3
                ));
                Owl_Form::print_hidden(array(
                    'name' => "certifications_hidden[$i]",
                    'value' => $certifications[$i],
                    'class' => 'multi-input-hidden'
                ));
                echo '<a href="#" rel="input-certifications" class="delete-certification-input info-extra delete"><span>' . __("Delete") . '</span></a>';
                echo "</div>";
            }
            echo "<div>";
            Owl_Form::print_textarea(array(
                'name' => "certifications[$i]",
                'value' => trim(Owl_Format::esc_html(__($certifications[$i], true, true))),
                'class' => 'form-textarea multi-input last',
                'rows' => 3
            ));
            Owl_Form::print_hidden(array(
                'name' => "certifications_hidden[$i]",
                'value' => $certifications[$i],
                'class' => 'multi-input-hidden'
            ));
            echo '<a href="#" rel="input-certifications" class="delete-certification-input info-extra delete"><span>' . __("Delete") . '</span></a>';
            echo '<a href="#" rel="input-certifications" class="add-certification-input info-extra add"><span>' . __("Add") . '</span></a>';
            echo "</div>";
        }
        echo '</td>';
        echo '</tr>';

        //Ajax feedback
        echo '<tr>';
        echo '<td colspan="2">';
        Owl_Default_Content::print_ajax_feedback(false);
        echo '</td>';
        echo '</tr>';

        //Button
        echo '<tr>';
        echo '<td class="form-button-pane" colspan="2">';
        echo '<img src="' . Owl_Link::image_url(false) . 'default/ajax-load.gif" class="ajax-load" alt="Ajax load" />';
        Owl_Form::print_button(array(
            'name' => 'submit',
            'value' => __('Save'),
            'class' => 'form-button info-ajax-submit',
            'title' => 'certifications-edit'
        ));
         Owl_Form::print_button(array(
            'name' => 'cancel',
            'value' => __('Cancel'),
            'class' => 'form-button info-cancel',
            'title' => 'certifications'
        ));
        echo '</td>';
        echo '</tr>';


        echo '</tbody>';
        echo '</table>';
        echo '</form>';
    }

    function print_avatar_form() {
        $personal_info = $this->get_personal();
        echo '<form action="' . Owl_Link::ajax_url(false) . 'info-ajax.php" method="POST" id="avatar-edit" enctype="multipart/form-data">' . "\n";
        Owl_Form::print_hidden(array(
            "name" => "action",
            "value" => "edit_avatar"
        ));
        echo '<div style="text-align:center;margin-bottom: 10px;" id="avatar-file-image">';
        Owl_Form::print_file_image(array(
            "name" => "avatar",
            "value" => empty($personal_info["avatar"]) ? "" : Owl_Link::site_url(false) . $personal_info["avatar"],
            "width" => 300,
            'description' => __("Upload your avatar here. The image size should be 300px width.")
        ));
        echo "</div>";
        echo '<div class="form-button-pane">';
        echo '<img src="' . Owl_Link::image_url(false) . 'default/ajax-load.gif" class="ajax-load" alt="Ajax load" />';
        Owl_Form::print_button(array(
            'name' => 'submitForm',
            'value' => __('Save'),
            'class' => 'form-button avatar-ajax-submit',
            'title' => 'avatar-edit'
        ));
         Owl_Form::print_button(array(
            'type' => 'reset',
            'name' => 'cancel',
            'value' => __('Cancel'),
            'class' => 'form-button avatar-cancel',
            'title' => 'avatar'
        ));
        echo '</div>';
        Owl_Default_Content::print_ajax_feedback(false);
        echo '</form>';
    }

    function print_password_form() {
        echo '<form action="' . Owl_Link::ajax_url(false) . 'user-ajax.php" method="POST" id="password-edit">';
        Owl_Form::print_hidden(array(
            "name" => "action",
            "value" => "edit_password"
        ));
        echo '<table class="form-table" border="0" cellspacing="0" cellpadding="0">';
        echo '<tbody>';

        //Old pass
        echo '<tr>';
        echo '<th>';
        Owl_Form::print_label(array(
            'value' => __("Old password"),
            'for' => "old_password"
        ));
        echo '</th>';
        echo '<td>';
        Owl_Form::print_textbox(array(
            'name' => 'old_password',
            'type' => 'password',
            'id' => 'old_password'
        ));
        echo '</td>';
        echo '</tr>';

        //New pass
        echo '<tr>';
        echo '<th>';
        Owl_Form::print_label(array(
            'value' => __("New password"),
            'for' => "new_password"
        ));
        echo '</th>';
        echo '<td>';
        Owl_Form::print_textbox(array(
            'name' => 'new_password',
            'type' => 'password',
            'id' => 'new_password',
            'class' => 'form-textbox ' . Owl_Functions::build_validate_string(array('required', 'minlength:6'))
        ));
        echo '</td>';
        echo '</tr>';

        //Password Retype
        echo '<tr>';
        echo '<th>';
        Owl_Form::print_label(array(
            'value' => __("Password retype"),
            'for' => "password-retype"
        ));
        echo '</th>';
        echo '<td>';
        Owl_Form::print_textbox(array(
            'name' => 'password_retype',
            'type' => 'password',
            'id' => 'password-retype',
            'class' => 'form-textbox ' . Owl_Functions::build_validate_string(array('required'))
        ));
        echo '</td>';
        echo '</tr>';

        //Ajax feedback
        echo '<tr>';
        echo '<td colspan="2">';
        Owl_Default_Content::print_ajax_feedback(false);
        echo '</td>';
        echo '</tr>';

        //Button
        echo '<tr>';
        echo '<td class="form-button-pane" colspan="2">';
        echo '<img src="' . Owl_Link::image_url(false) . 'default/ajax-load.gif" class="ajax-load" alt="Ajax load" />';
        Owl_Form::print_button(array(
            'name' => 'submit',
            'value' => __('Save'),
            'class' => 'form-button ajax-submit',
            'title' => 'password-edit'
        ));
         Owl_Form::print_button(array(
            'name' => 'cancel',
            'type' => 'reset',
            'value' => __('Cancel'),
            'title' => 'certifications'
        ));
        echo '</td>';
        echo '</tr>';

        echo '</tbody>';
        echo '</table>';
        echo '</form>';
    }

    function print_form_control($rel) {
        echo '<a class="form-toggle" href="#" rel="' . $rel . '">';
        echo '<span>' . __("Edit"). '</span>';
        echo '</a>';
        echo '<a class="form-close" href="#" rel="' . $rel . '">';
        echo '<span>' . __("Close") . '</span>';
        echo '</a>';
    }
}

